<!-- 
此组件初始化时不会自动加载数据，请在mounted中 this.$refs.[].initData()
如果放在dialog里面的吗，请在dialog的open事件中用this.$nextTick进行加载
 -->
<template>
  <div>
    <list id-key="id" ref="list" unit="账单" :disabled="disabled" :show-query="showQuery" show-checkbox
      :query-params="queryParams" :expand-query="expandQuery" page @get-data="onGetData" :data="data" :total="total"
      custom-get-data>
      <template #toolbar-left>
        <slot name="toolbar-left"></slot>
      </template>
      <template #query>
        <!-- <el-form-item label="ID">
          <el-input v-model.trim="queryParams.id" clearable></el-input>
        </el-form-item> -->
        <div>
          <el-form-item label="账单号">
            <el-input v-model.trim="queryParams.no" placeholder="账单号" clearable></el-input>
          </el-form-item>          
          <el-form-item label="类型">
            <el-select v-model="queryParams.types" clearable multiple collapse-tags>
              <el-option label="应收" :value="0"></el-option>
              <el-option label="应付" :value="1"></el-option>
              <el-option label="代理" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="账单状态">
            <el-select v-model="queryParams.statuses" clearable multiple collapse-tags>
              <el-option label="已创建" :value="0"></el-option>
              <el-option label="锁单" :value="1"></el-option>
              <el-option label="部分核销" :value="2"></el-option>
              <el-option label="完全核销" :value="3"></el-option>
              <el-option label="部分到账" :value="4"></el-option>
              <el-option label="全部到账" :value="5"></el-option>
              <el-option label="审核" :value="6"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="客户名称">
            <el-input v-model.trim="queryParams.customerName" placeholder="客户名称" clearable></el-input>
          </el-form-item>  
        </div>
        <div>
          <el-form-item label="业务号">
            <el-input v-model.trim="queryParams.shipmentServiceNo" placeholder="业务号" clearable></el-input>
          </el-form-item>
          <el-form-item label="业务类型">
            <el-select v-model="queryParams.shipmentServiceTypes" clearable multiple collapse-tags>
              <el-option label="出口" :value="1"></el-option>
              <el-option label="进口" :value="2"></el-option>
              <el-option label="其它" :value="3"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="ID">
            <el-input v-model="queryParams.idString" placeholder="ID，以,或空格分隔" clearable
              style="width:800px;max-width:none"></el-input>
          </el-form-item>
        </div>
      </template>
      <template #column>
        <el-table-column prop="no" width="200" label="账单号">
          <template #default="{ row }">
            <span class="c-link" @click="openDetail(row.id)">{{ row.no || "无" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="typeName" width="80" align="center" label="类型">
        </el-table-column>
        <el-table-column prop="statusName" width="80" align="center" label="状态" />
        <el-table-column prop="companyName" width="130" label="公司名称">
        </el-table-column>
        <el-table-column prop="customerName" min-width="150" label="客户名称" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="accountDate" width="120" label="计费日期" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.accountDate | toDateString }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="dueDate" width="120" label="到期日期" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.dueDate | toDateString }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="shipmentServiceNo" width="150" label="业务号" sortable="custom">
        </el-table-column>
        <el-table-column prop="shipmentServiceTypeName" width="100" label="业务类型" sortable="custom">
        </el-table-column>
        <el-table-column prop="creatorUserName" width="80" label="创建人" show-overflow-tooltip />
        <el-table-column prop="creationTime" width="120" label="创建时间" sortable="custom">
          <template v-slot="{ row }">
            <span>{{ row.creationTime | toShortDatetimeString }}</span>
          </template>
        </el-table-column>
        <!-- slot[column] -->
        <slot name="column"></slot>
        <!--/ slot[column]-->
      </template>
    </list>
    <detail-dialog ref="detailDialog" />
  </div>
</template>
<script>
import listMixin from "@/mixins/list";
import list from "@/components/common/list";
import detailDialog from "./detailDialog";
import api from "@/api/fam/bill";
export default {
  mixins: [listMixin],
  components: {
    list,
    detailDialog
  },
  props: {},
  data() {
    return {
      //查询条件字段
      queryParams: {
        invoiceNo: "",
        invoiceCode: "",
        serialNo: "",
        buyerTitleName: "",
        sellerTitleName: "",
        statuses: [],
      },
      data: [],
      total: 0
    };
  },
  methods: {
    getStatusType(status) {
      var text = "";
      switch (status) {
        case 0:
          text = "info";
          break;
        case 1:
          text = "";
          break;
        case 2:
          //作废
          text = "info";
          break;
        case 3:
          //冲红
          text = "warning";
          break;
        case 6:
          text = "danger";
          break;
      }
      return text;
    },
    openInvoice(url) {
      window.open(url);
    },
    openDetail(id) {
      this.$refs.detailDialog.openDetail(id);
    },
    onGetData(params) {
      this.$refs.list.loading(true);
      api.getPageList(params).then(res => {
        if (res.code != 0) {
          return;
        }
        this.data = res.data.list;
        this.total = res.data.total;
        this.$refs.list.loading(false);
      })
    },
    getCheckedRows() {
      return this.$refs.list.getCheckedRows();
    },
    reload() {
      this.$refs.list.reload();
    }
  },
};
</script>